import { removeWindowById } from '@e/utils/global';
import { WindowObject } from '@p/main-windowObject';
import { removeArrayElment } from '@e/methods/array';

export function bindWindowEvent(obj: WindowObject) {
	// 窗口关闭
	obj.window.on('closed', () => {
		removeWindowById(obj.id);
	});

	// 窗口加载完毕
	obj.window.webContents.on('did-finish-load', () => {
		const removes: number[] = [];

		obj.service.event.load.forEach((item, i) => {
			item.listener();

			if (item.once) {
				removes.push(i);
			}
		});

		if (removes.length > 0) removeArrayElment(obj.service.event.load, removes);
	});
}
